<template>
  <el-row :gutter="40" class="panel-group">
    <el-carousel :autoplay="false" trigger="click" height="250px">
      <el-carousel-item>
        <!-- <img src="@/assets/day/none.png" alt="" style="width: 100%;height: 100%;object-fit: contain;"
          v-show="biNumberItem.length <= 0"> -->

        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" v-for="(item, index) in biNumberSku.slice(0, 8)"
          :key="index">
          <div class="card-panel" :class="{ highlight: highlighted.includes(item.name) }"
            @click="handleSetLineChartData(item.name)">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>

            <div class="card-panel-description">
              <div class="card-panel-text">
                <!-- 销售金额 -->
                {{ item.name }}
                <span @click="handleClick(item.name)">
                  <handlepopover :popoverInput="popoverInput" />
                </span>
              </div>
              <div v-if="item.value == null" class="card-panel-num">未更新</div>
              <div v-else>
                <!-- :decimals="1" -->
                <count-to :start-val="0" v-if="item.name.includes('数')" :end-val="item.value" :duration="duration"
                  class="card-panel-num" />
                <count-to :start-val="0" v-else-if="item.name.includes('率')" :decimals="2" :end-val="item.value"
                  :duration="duration" class="card-panel-num" />
                <count-to :start-val="0" v-else :end-val="item.value" :duration="duration" class="card-panel-num" />
                <!-- <span v-show="item.name.includes('率')">%</span> -->
              </div>
            </div>
            <div class="card-panel-right">
              <div class="flex">
                <div class="card-panel-text">环比</div>
                <div class="card-panel-num">
                  <i class="el-icon-caret-top" v-if="item.chainSign == true" />
                  <i class="el-icon-caret-bottom" v-else-if="item.chainSign == false" />
                  <count-to :start-val="0" :decimals="2" v-if="item.chain !== null" :end-val="item.chain"
                    :duration="duration" />
                  <span v-if="item.chain == null">-</span>%
                </div>
              </div>
              <div class="flex">
                <div class="card-panel-text">同比</div>
                <div class="card-panel-num">
                  <i class="el-icon-caret-top" v-if="item.yoySign == true" />
                  <i class="el-icon-caret-bottom" v-else-if="item.yoySign == false" />
                  <count-to :start-val="0" :decimals="2" v-if="item.yoy !== null" :end-val="item.yoy"
                    :duration="duration" />
                  <span v-if="item.yoy == null">-</span>%
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-carousel-item>
      <el-carousel-item>
        <!-- <img src="@/assets/day/none.png" alt="" style="width: 100%;height: 100%;object-fit: contain;"
          v-show="biNumberItem.length <= 0"> -->

        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col" v-for="(item, index) in biNumberSku.slice(8, 9)"
          :key="index">
          <div class="card-panel" :class="{ highlight: highlighted.includes(item.name) }"
            @click="handleSetLineChartData(item.name)">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="peoples" class-name="card-panel-icon" />
            </div>

            <div class="card-panel-description">
              <div class="card-panel-text">
                <!-- 销售金额 -->
                {{ item.name }}
                <span @click="handleClick(item.name)">
                  <handlepopover :popoverInput="popoverInput" />
                </span>
              </div>
              <div v-if="item.value == null" class="card-panel-num">未更新</div>
              <div v-else>
                <!-- :decimals="1" -->
                <count-to :start-val="0" v-if="item.name.includes('数')" :end-val="item.value" :duration="duration"
                  class="card-panel-num" />
                <count-to :start-val="0" v-else-if="item.name.includes('率')" :decimals="2" :end-val="item.value"
                  :duration="duration" class="card-panel-num" />
                <count-to :start-val="0" v-else :end-val="item.value" :duration="duration" class="card-panel-num" />
                <!-- <span v-show="item.name.includes('率')">%</span> -->
              </div>
            </div>
            <div class="card-panel-right">
              <div class="flex">
                <div class="card-panel-text">环比</div>
                <div class="card-panel-num">
                  <i class="el-icon-caret-top" v-if="item.chainSign == true" />
                  <i class="el-icon-caret-bottom" v-else-if="item.chainSign == false" />
                  <count-to :start-val="0" :decimals="2" v-if="item.chain !== null" :end-val="item.chain"
                    :duration="duration" />
                  <span v-if="item.chain == null">-</span>%
                </div>
              </div>
              <div class="flex">
                <div class="card-panel-text">同比</div>
                <div class="card-panel-num">
                  <i class="el-icon-caret-top" v-if="item.yoySign == true" />
                  <i class="el-icon-caret-bottom" v-else-if="item.yoySign == false" />
                  <count-to :start-val="0" :decimals="2" v-if="item.yoy !== null" :end-val="item.yoy"
                    :duration="duration" />
                  <span v-if="item.yoy == null">-</span>%
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-carousel-item>
    </el-carousel>
  </el-row>
</template>

<script>
import CountTo from "vue-count-to";
import handlepopover from "@/views/components/mypopover/click.vue";
import {
  listSysMenuProperty,
  getSysMenuProperty,
  delSysMenuProperty,
  addSysMenuProperty,
  updateSysMenuProperty,
} from "@/api/conf/SysMenuProperty";
export default {
  components: {
    CountTo,
    handlepopover,
  },
  model: {
    prop: "biNumberSku",
  },
  props: {
    biNumberSku: {
      type: Array,
      default: () => [],
    },
    biNumberOfItem: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      popoverInput: "",
      duration: 1000,
      highlighted: ["库存总金额", "产品库存总金额", "配件库存总金额"], // 初始化时，前两个元素高亮
    };
  },
  methods: {
    handleClick(type) {
      if (!type) {
        return;
      }
      let obj = {
        component: "chart/admin/index",
        property: type,
        path: "库存总览",
      };
      listSysMenuProperty(obj).then((response) => {
        this.popoverInput = response.rows[0]
          ? response.rows[0].propertyInfo
          : "未定义";
        type = "";
      });
    },
    handleSetLineChartData(type) {
      // const m = ["messages", "shoppings"]
      if (this.highlighted.includes(type)) {
        return;
      }
      // 移除旧的高亮元素
      this.highlighted.shift();
      // 添加新的高亮元素
      this.highlighted.push(type);

      console.log(JSON.stringify(this.highlighted));
      this.$emit("handleSetLineSkuData", type);
    },
  },
};
</script>

<style lang="scss">
.el-carousel__indicator--horizontal {
  display: none;
}

.highlight {
  border-top: 5px solid #36a3f7;
}

i.el-icon-caret-top::before {
  color: #f00;
  /* 这将把颜色改为红色 */
}

i.el-icon-caret-bottom::before {
  color: green;
  /* 这将把颜色改色 */
}

//上三角
.increase {
  width: 10px;
  height: 10px;
  margin: 0 0 3px 5px;
  border-color: transparent transparent red transparent;
  border-style: solid;
  border-width: 3px;
}

//下三角
.decrease {
  width: 10px;
  height: 10px;
  margin: 3px 0 0 5px;
  border-color: green transparent transparent transparent;
  border-style: solid;
  border-width: 3px;
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    position: relative;
    overflow: hidden;
    height: 108px;
    color: #666;
    font-size: 12px;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    cursor: pointer;
    // border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      padding: 16px;
      margin: 14px 0 0 14px;
      border-radius: 6px;
      transition: all .38s ease-out;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: left;
      margin: 26px;
      margin-left: 10px;
      font-weight: bold;

      .card-panel-text {
        margin-bottom: 12px;
        color: rgba(0, 0, 0, .45);
        font-size: 13px;
        // line-height: 18px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }

    .card-panel-right {
      float: right;
      margin: 26px;
      margin-right: 10px;

      // text-align: center;
      font-weight: bold;

      .flex {
        display: flex;
      }

      .card-panel-text {
        margin-bottom: 12px;
        color: rgba(0, 0, 0, .45);
        font-size: 14px;
        line-height: 18px;
        text-align: center;
      }

      .card-panel-num {
        display: flex;
        align-items: center;
        margin-bottom: 12px;
        font-size: 14px;
      }
    }
  }
}

@media (max-width: 550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      float: none !important;
      display: block;
      margin: 14px auto !important;
    }
  }
}
</style>
